$(document).ready(function(){
	console.log('classfyModuleClassifyType',window.parent.classfyModuleClassifyType);

	$.ajax({
		type: "POST",
		url: '/web/bi/business/getInfoByClassifyType',
		data: {"classifyType":window.parent.classfyModuleClassifyType},
		async: true,
		success: function (data) {
			console.log('data',data);
			if (data.code == 0) {
				//收入
				$('#yesterdayCount1').text(data.yesterdayIncome);
				$('#monthAcc1').text(data.monthAccIncome);
				$('#relativeByMonth1').text(data.relativeByMonthIncome+"%");
				$('#sameRatioByMonth1').text(data.sameRatioByMonthIncome+"%");
				$('#yearAcc1').text(data.yearAccIncome);
				$('#relativeByYear1').text(data.relativeByYearIncome+"%");
				//支出
				$('#yesterdayCount2').text(data.yesterdayOutcome);
				$('#monthAcc2').text(data.monthAccOutcome);
				$('#relativeByMonth2').text(data.relativeByMonthOutcome+"%");
				$('#sameRatioByMonth2').text(data.sameRatioByMonthOutcome+"%");
				$('#yearAcc2').text(data.yearAccOutcome);
				$('#relativeByYear2').text(data.relativeByYearOutcome+"%");
				//环比
				$('#yesterdayCount3').text(data.yesterdayProfit);
				$('#monthAcc3').text(data.monthAccProfit);
				$('#relativeByMonth3').text(data.relativeByMonthProfit+"%");
				$('#sameRatioByMonth3').text(data.sameRatioByMonthProfit+"%");
				$('#yearAcc3').text(data.yearAccProfit);
				$('#relativeByYear3').text(data.relativeByYearProfit+"%");

				//折线图
				loadLirun(data.monthList,data.totalListByIncome,data.totalListByOutcome,data.totalListByProfit); // 初始加载利润折线图

				var monthList = data.monthList;
				//列表1
				//表头
				var tableHead1 = '<th width="120">收入项目</th>';
				for(var i=0;i<monthList.length;i++){
					tableHead1 += '<th width="120">'+monthList[i]+'</th>';
				}
				$('#tableHead1').html(tableHead1);
				//表数据
				var tableBody1 = '';
				var tableListByIn = data.tableListByIn;
				for(var i=0;i<tableListByIn.length;i++){
					var row = tableListByIn[i];
					tableBody1 += '<tr>';
					tableBody1 += '<td>'+row.integrityType+'</td>';
					tableBody1 += '<td>'+row.month1+'</td>';
					tableBody1 += '<td>'+row.month2+'</td>';
					tableBody1 += '<td>'+row.month3+'</td>';
					tableBody1 += '<td>'+row.month4+'</td>';
					tableBody1 += '<td>'+row.month5+'</td>';
					tableBody1 += '<td>'+row.month6+'</td>';
					tableBody1 += '<td>'+row.month7+'</td>';
					tableBody1 += '<td>'+row.month8+'</td>';
					tableBody1 += '<td>'+row.month9+'</td>';
					tableBody1 += '<td>'+row.month10+'</td>';
					tableBody1 += '<td>'+row.month11+'</td>';
					tableBody1 += '<td>'+row.month12+'</td>';
					tableBody1 += '</tr>';
				}
				$('#tableBody1').html(tableBody1);

				//列表2
				//表头
				var tableHead2 = '<th width="120">支出项目</th>';
				for(var i=0;i<monthList.length;i++){
					tableHead2 += '<th width="120">'+monthList[i]+'</th>';
				}

				$('#tableHead2').html(tableHead2);

				//表数据
				var tableBody2 = '';
				var tableListByOut = data.tableListByOut;
				for(var i=0;i<tableListByOut.length;i++){
					var row = tableListByOut[i];
					tableBody2 += '<tr>';
					tableBody2 += '<td>'+row.integrityType+'</td>';
					tableBody2 += '<td>'+row.month1+'</td>';
					tableBody2 += '<td>'+row.month2+'</td>';
					tableBody2 += '<td>'+row.month3+'</td>';
					tableBody2 += '<td>'+row.month4+'</td>';
					tableBody2 += '<td>'+row.month5+'</td>';
					tableBody2 += '<td>'+row.month6+'</td>';
					tableBody2 += '<td>'+row.month7+'</td>';
					tableBody2 += '<td>'+row.month8+'</td>';
					tableBody2 += '<td>'+row.month9+'</td>';
					tableBody2 += '<td>'+row.month10+'</td>';
					tableBody2 += '<td>'+row.month11+'</td>';
					tableBody2 += '<td>'+row.month12+'</td>';
					tableBody2 += '</tr>';
				}
				$('#tableBody2').html(tableBody2);


			} else {
				alert(data.msg);
			}
		}, error: function() {
			alert("操作失败，请稍后再试！", { icon: 2 });
		}
	});


});


/*
 * 加载折线图
 */
function loadLirun(monthList,totalListByIncome,totalListByOutcome,totalListByProfit) {

	var data = {
		    "xdataArr": monthList,//横坐标数据
		    "legend": { "data": ["收入","支出","利润"] },
		    "series": [
		                 {
		                     "name": "收入",
		                     "type": "line",
		                     "data": totalListByIncome
		                 },
		                 {
		                     "name": "支出",
		                     "type": "line",
		                     "data": totalListByOutcome
		                 },
		                 {
		                     "name": "利润",
		                     "type": "line",
		                     "data": totalListByProfit
		                 }
		             ]
		         };
	initEcharts('id_echarts', data);
}

//补零函数
function zero(n) {
	return n >= 10 ? n : '0' + n
}

/**
 */
function initEcharts(id, data) {
	// 处理yaxisIndex

	const colors = ['#5470C6', '#91CC75', '#EE6666'];
	var option = {
	  color: colors,
	  tooltip: {
	    trigger: 'axis',
	    axisPointer: {
	      type: 'cross'
	    }
	  },
	  grid: {
			left: '2%',
			right: '2%',
			bottom: '2%',
		    containLabel: true
	  },
	  toolbox: {
	    feature: {
	      dataView: { show: false, readOnly: false },
	      restore: { show: false },
	      saveAsImage: { show: false }
	    }
	  },
	  legend: data.legend,
	  xAxis: [
	    {
	      type: 'category',
	      axisTick: {
	        alignWithLabel: true
	      },
	      // prettier-ignore
	      data: data.xdataArr // X轴数组
	    }
	  ],
	  yAxis: [
	    {
	      type: 'value',
			name: '金额',
	      position: 'left',
	      alignTicks: true,
	      axisLine: {
	        show: true,
	        lineStyle: {
	          color: colors[0]
	        }
	      },
	      axisLabel: {
	        formatter: '{value}'
	      }
	    }

	  ],
	  series: data.series

	};
	echarts.init(document.getElementById(id)).setOption(option, true);
}


